home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: returning an array from function
- Date: 3 Apr 1996 12:32:49 GMT
- Organization: systems hk
- Message-ID: <4jtr5h$h2s@nadine.teleport.com>
- References: <4jstd8$kh0@news1.sunbelt.net>
- NNTP-Posting-Host: ip-pdx01-07.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- bourne@infoave.net (Rick Huebner) wrote:
- >I have looked in several texts and looked through the faq for this question
- >and can't find a reference for my answer. I am trying to return an array, or
- >a pointer to the array, from a function. I have seen several examples of
- >returning a pointer, but it doesn't seem to work for me. My function is going
- >to return an array of integers where 1-80 of them will be significant. The
- >calling function will know how many integers are expected and will read them
- >off the array....If I can get the pointer back to the array. A friend of mine
- >told me to just make the array a global, but I don't want to do that if I can
- >help it. I would even resort to a recursive function that will pass the
- >integers back one at a time if that is possible. Does anyone have any
- >suggestions? I am open to anything and will go looking if you can tell me
- >where(hopefully online somewhere).
- >
- Rick,
- I didn't know whether you meant returning the array as the function value, or
- simply as an argument to/from the function. Assuming the latter:
-
- int main ( void )
- {
- int myArray[MAXSIZE];
- int nElems;
- ...
- ...
- myFunction( myArray,&nElems );
- ...
- }
-
- void myFunction ( int array[], int *nelems )
- {
- ...
- use the 'array'
- ...
- return;
- }
-
- Yours, Geoff Houck
-
-